// pages/ucenter/my-funds/my-funds.js
const app = getApp();
import * as API_Shop from '../../api/shop'
import {
  Foundation
} from '../../ui-utils/index.js'
Page({

  /**
   * 页面的初始数据
   */
  data: {
    shop_status: '',
    shop_name:"",
    userInfo:null
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    if(wx.getStorageSync('refresh_token')){
      const userInfo = wx.getStorageSync('user')
      console.log(userInfo)
      this.setData({userInfo})
    }
    
  },
  applyJoin() {
    if(!wx.getStorageSync('refresh_token')){
      wx.showModal({
        title: '提示',
        content: '您还未登录，要现在去登录吗？',
        success(res) {
          if(res.confirm) {
            wx.navigateTo({ url: '/pages/auth/login/login' })
            return false
          }
        }
      })
      return;
    }
    wx.showLoading({
      title: '加载中',
    })
    API_Shop.initApplyShop().then(res=>{
      wx.hideLoading()
      wx.navigateTo({
        url: "/ucenter/my-joinusstep/my-joinusstep?mobile="+this.data.userInfo.mobile
      })
    })
  },
  continueJoin() {
    wx.showLoading({
      title: '加载中',
    })
    wx.navigateTo({
      url: "/ucenter/my-joinusstep/my-joinusstep?mobile="+this.data.userInfo.mobile
    })
    wx.hideLoading()
  },
  againJoin() {
    wx.showLoading({
      title: '加载中',
    })
    API_Shop.initApplyShop().then(res=>{
      wx.hideLoading()
      wx.navigateTo({
        url: "/ucenter/my-joinusstep/my-joinusstep?mobile="+this.data.userInfo.mobile
      })
    })
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */

  //TODO 判断是否已经申请，显示不同结果
  onShow: function () {
    if(wx.getStorageSync('refresh_token')){
      API_Shop.getApplyShopInfo().then(res => {
        this.setData({
          shop_status: res.shop_disable,
          shop_name:res.shop_name
        })
      })
    }
    
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})